package com.zc.study.thread.多线程第四章节.thread4_1_10;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Service {
    private ReentrantLock lock = new ReentrantLock();
    public void method1 (){
        try {
            System.out.println("当前锁定的个数 begin::" + lock.getHoldCount());
            lock.lock();
            System.out.println("当前锁定的个数1::" + lock.getHoldCount());
            method2();
            method3();
            method4();
            System.out.println("当前锁定的个数 ::" + lock.getHoldCount());
        }finally {
            lock.unlock();
            System.out.println("当前锁定的个数 end::"+lock.getHoldCount());
        }
    }
    public void method2 (){
        try {
            lock.lock();
            System.out.println("当前锁定的个数2::" + lock.getHoldCount());

        }finally {
            lock.unlock();
        }
    }
    public void method3 (){
        try {
            lock.lock();
            System.out.println("当前锁定的个数3::" + lock.getHoldCount());
        }finally {
            lock.unlock();
        }
    }
    public void method4 (){
        try {
            lock.lock();
            System.out.println("当前锁定的个数4::" + lock.getHoldCount());
        }finally {
            lock.unlock();
        }
    }
}
